import { useFetch } from 'nuxt/app'
import { useUserManagerStore } from '~/stores/userManagerStore'

type useFetchType = typeof useFetch

export const useAPIFetch: useFetchType = (path, options = {}) => {
  const config = useRuntimeConfig()
  const userManagerStore = useUserManagerStore()
  return useFetch(path, {
    ...options,
    baseURL: config.public.baseURL,
    headers: [
      ['Authorization', 'Bearer ' + (userManagerStore.user?.access_token || '')]
    ]
  })
}
